<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../static/css/style.css">
    <script src="../static/js/jquery-3.7.1.js"></script>
    <title>中交业务组</title>
</head>
<body>
<div class="login-wrapper">
    <form method="POST" action="/login" class="form">
        <input type="hidden" name="came_from" value="{{ came_from }}"/>
        <img src="../static/img/1.jpg" alt="">
        <h2>密码登录</h2>
        <div class="input-group">
            <input type="text" name="loginUser" id="loginUser" autocomplete="off" required>
            <label for="loginUser">账号</label>
        </div>
        <span id="error_msg" style="color: red;">{{ msg }}</span>
        <div class="input-group">
            <input type="password" name="loginPassword" id="loginPassword" required>
            <label for="loginPassword">密码</label>
        </div>
        <div class="choose">
        <input type="submit" value="登录" class="submit-btn" name="form.submitted">
        </div>
    </form>

</div>
</body>
<script>
    $(function () {
        $("#loginUser").blur(function () {
            // 1.获取表单输入的内容
            var loginUser = $("#loginUser").val();
            // 2.发送ajax请求
            $.ajax({
                url: '/login/user_verify', // ajax 请求的目标位置
                type: 'get', // 请求方式
                data: {'loginUser': loginUser}, // 要给后端传递的数据。
                success: function (data) {
                    // console.log(data);
                    var code = data.code;
                    if (code == '200') {
                        $("#error_msg").text('');
                    } else {
                        $("#error_msg").text(data.msg);
                    }
                },
                error: function (data) {
                    alert('error');
                }
            })
        });
    })
</script>
</html>